#include <iostream>
#include"udpsocket.hpp"
#include<memory>
#include<unistd.h>
#include<functional>
#include"Route.hpp"
#include"ThreadPool.hpp"
#include"Log.hpp"
using namespace ThreadPoolMudole;
using task_t=std::function<void()>;
int main(int argc,char*argv[]){
    if(argc!=2){
        std::cout<<"Usage: "<<argv[0]<<" port"<<std::endl;
        return 1;
    }
    Route t;
    std::unique_ptr<ThreadPool<task_t>> pool=std::make_unique<ThreadPool<task_t>>();
    pool->Start();
    uint16_t port=std::stoi(argv[1]);
    std::unique_ptr<UdpSocket> sock=std::make_unique<UdpSocket>(port,[&pool,&t](int sockfd,const std::string &msg,netAddr &msg_sender){
        LOG(LogLevel::INFO)<<"in message route";
        task_t f = std::bind(&Route::MessageRoute,t,sockfd,msg,msg_sender);
        pool->Enqueue(f);
    });
    sock->Init();
    sock->Start();
    return 0;
}